package com.evil.kingdom.service.action.impl;

import com.evil.common.core.util.StreamUtil;
import com.evil.kingdom.pojo.entity.action.RoutePosition;
import com.evil.kingdom.service.action.PositionService;
import com.evil.kingdom.utils.DijkstraUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * 坐标服务
 *
 * @author liyang
 * @date 2024-05-24 09:25
 */
@Slf4j
@Service
@AllArgsConstructor
public class PositionServiceImpl implements PositionService {

    @Override
    public List<String> calShortest(Collection<RoutePosition> routes, String depart, String dest) {
        Map<String, List<RoutePosition>> graph = StreamUtil.groupK(routes, RoutePosition::getDepartName);
        return DijkstraUtil.shortestPathName(graph, depart, dest);
    }

    @Override
    public LinkedList<RoutePosition> warfare(Collection<RoutePosition> routes, String depart, String dest) {
        Map<String, List<RoutePosition>> graph = StreamUtil.groupK(routes, RoutePosition::getDepartName);
        return DijkstraUtil.shortestPath(graph, depart, dest);
    }
}
